package com.yonyou.sto.modules.ims.controller;


import com.yonyou.sto.common.api.CommonResult;
import com.yonyou.sto.modules.ims.service.ImsBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.security.Principal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author aegon
 * @since 2020-10-10
 */
@RestController
@RequestMapping("/server/ims/imsBill")
@Api(tags = "ImsBillController", description = "发票管理")
public class ImsBillController {

    @Resource
    private ImsBillService billService;

    @ApiOperation("分页条件查询发票列表")
    @GetMapping(value = "/list")
    public CommonResult<Map<String, Object>> list(Principal principal,
                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "billSerial", required = false) String billSerial,
                                                  @RequestParam(value = "billNo", required = false) String billNo,
                                                  @RequestParam(value = "billCode", required = false) String billCode,
                                                  @RequestParam(value = "billSn", required = false) String billSn,
                                                  @RequestParam(value = "sellerName", required = false) String sellerName,
                                                  @RequestParam(value = "buyerName", required = false) String buyerName,
                                                  @RequestParam(value = "status", required = false) Integer status,
                                                  @RequestParam(value = "billType", required = false) Integer billType,
                                                  @RequestParam(value = "startTime", required = false) String startTime,
                                                  @RequestParam(value = "endTime", required = false) String endTime) {
        if (principal == null) return CommonResult.unauthorized(null);

        return billService.list(principal.getName(), pageSize, pageNum, billNo, billCode, billSerial, billSn, sellerName, buyerName, status, billType, startTime, endTime);
    }
    @ApiOperation("分页条件查询发票列表")
    @GetMapping(value = "/listApply")
    public CommonResult<Map<String, Object>> listApply(Principal principal,
                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "billSerial", required = false) String billSerial,
                                                  @RequestParam(value = "billNo", required = false) String billNo,
                                                  @RequestParam(value = "billCode", required = false) String billCode,
                                                  @RequestParam(value = "billSn", required = false) String billSn,
                                                  @RequestParam(value = "sellerName", required = false) String sellerName,
                                                  @RequestParam(value = "buyerName", required = false) String buyerName,
                                                  @RequestParam(value = "status", required = false) Integer status,
                                                  @RequestParam(value = "billType", required = false) Integer billType,
                                                  @RequestParam(value = "startTime", required = false) String startTime,
                                                  @RequestParam(value = "endTime", required = false) String endTime) {
        if (principal == null) return CommonResult.unauthorized(null);

        return billService.list(principal.getName(), pageSize, pageNum, billNo, billCode, billSerial, billSn, sellerName, buyerName, status, billType, startTime, endTime);
    }
    @ApiOperation("发票明细")
    @GetMapping(value = "/info")
    public CommonResult info(@RequestParam Long id) {
        return billService.info(id);
    }

    @ApiOperation("批量作废发票")
    @PostMapping(value = "/cancel")
    public CommonResult<String> cancel(@RequestBody List<Long> ids) {
        return billService.cancel(ids);
    }

    @ApiOperation("红冲专用发票")
    @PostMapping(value = "/redSpecialBill")
    public CommonResult<String> redSpecialBill(@RequestParam List<Long> billIds) {
        return billService.redSpecialBill(billIds);
    }

}

